package com.uiao.stone.controller;

import com.uiao.stone.common.annotation.CurrentUser;
import com.uiao.stone.common.config.StrategyFactory;
import com.uiao.stone.common.enums.OrderType;
import com.uiao.stone.data.User;
import com.uiao.stone.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author cuihao
 * @date 2017/12/11
 */
@Controller
@RequestMapping(value = "usermanager")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("listUser")
    @ResponseBody
    public List<User> listUsers() {
        List<User> users = new ArrayList<>();
        System.out.println("listUsers");
        // users = userService.listUsers();
        // userService.order();
        StrategyFactory.getStrategy(OrderType.A).order();
        StrategyFactory.getStrategy(OrderType.B).order();

        return users;
    }

    @RequestMapping("findUser")
    @ResponseBody
    public User findUser(Integer userId) {
        User user = userService.findUserById(userId);
        return user;
    }

    @RequestMapping("notConDB")
    public String soutString(Map<String, Object> model, @CurrentUser String user) {
        String str = "这个请求没有连接数据库";
        model.put("str", str);
        model.put("user", user);
        System.out.println("当前用户为：" + user);
        return "nodb";
    }
}
